package services;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;
import security.UserAccount;
import security.UserAccountRepository;

@Service
@Transactional
public class UserAccountService {
	
	// Managed repository -----------------------------------------------------

		@Autowired
		private UserAccountRepository userAccountRepository;
		
		
		
		public UserAccount create() {
			return new UserAccount();
		}

		public void save(UserAccount userAccount) {
			Assert.notNull(userAccount);
			Assert.isNull(findByUsername(userAccount.getUsername()));
			userAccountRepository.save(userAccount);			
			
		}
		
		public UserAccount findByUsername(String username)
		{
			return userAccountRepository.findByUsername(username);
		}
	

}
